<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="title">
            <h2><a href="#" class="back" onclick="history.go(-1)"/>Pesquisar Folha de Pagamento</h2>
        </ui:define>

        <ui:define name="body">
            <p:panel styleClass="container_24 clearfix">
                <div class="buttonAction" style="float: right">
                    <p:button value="Adicionar" href="criarfolhapagamento.xhtml" icon="ui-icon-plusthick"
                              styleClass="ui-priority-primary"/>
                </div>
                <br/>
            </p:panel>

            <h:form id="folhaPagamentoForm" enctype="multipart/form-data">            
                <p:messages id="messages" closable="true" showDetail="true" autoUpdate="true"  />
                <p:panel id="dadosGeraisPanel" styleClass="container_24 clearfix">
                    <h2>Filtros</h2>

                    <p:outputLabel value="Data:" styleClass="grid_3" for="dataCalendar" />
                    <p:calendar id="dataCalendar" value="#{managerPesquisarFolhaPagamento.folhaPagamentoPesquisar.dataFolhaPagamento}"
                                showOn="both" locale="pt" yearRange="1900:2100" 
                                navigator="true" pattern="dd/MM/yyyy" styleClass="grid_9" />
                    <div class="clear" />

                    <p:outputLabel value="Secretaria:" styleClass="grid_3" for="secretariaInputText"/>
                    <p:inputText id="secretariaInputText" styleClass="grid_18" 
                                 readonly="true"
                                 value="#{managerPesquisarFolhaPagamento.secretariaPesquisar.nome}" />
                    <div class="smallActionButtons">
                        <p:commandButton icon="ui-icon-circle-plus" oncomplete="dlgSecretaria.show();"
                                         update="@this" process="@this"/>
                        <p:commandButton icon="ui-icon-trash" update=":folhaPagamentoForm:secretariaInputText"
                                         process="@this" immediate="true" 
                                         actionListener="#{managerPesquisarFolhaPagamento.removerSecretaria()}"/>
                    </div>

                    <div class="clear"/>
                    <br/>

                    <h2>Pessoa</h2>

                    <p:outputLabel id="personOutputLabel" value="Pessoa:" styleClass="grid_3" style="top: 6px" />
                    <div class="grid_8">
                        <p:selectOneRadio id="personRadioButton" value="#{managerPesquisarFolhaPagamento.funcionarioPesquisar.tipoDocumento}" >
                            <f:selectItems value="#{managerPesquisarFolhaPagamento.tipoDocumento}" />
                            <p:ajax event="change" update="@form" />
                        </p:selectOneRadio>
                    </div>
                    <div class="clear"/>

                    <p:outputLabel value="#{managerPesquisarFolhaPagamento.pessoaFisicaPesquisar ? 'CPF:' : 'CNPJ:'}" styleClass="grid_3"/>
                    <p:inputMask value="#{managerPesquisarFolhaPagamento.pessoaFisicaPesquisar ? managerPesquisarFolhaPagamento.funcionarioPesquisar.cpf : managerPesquisarFolhaPagamento.funcionarioPesquisar.cnpj}" 
                                 styleClass="grid_8" mask='999.999.999-99' 
                                 autocomplete="false" />
                    <div class="clear"/>

                    <p:outputLabel value="#{managerPesquisarFolhaPagamento.pessoaFisicaPesquisar ? 'Nome:' : 'Nome Fantasia:'}" styleClass="grid_3" for="nomeInputText"/>
                    <p:inputText id="nomeInputText" 
                                 value="#{managerPesquisarFolhaPagamento.pessoaFisicaPesquisar ? managerPesquisarFolhaPagamento.funcionarioPesquisar.nome : managerPesquisarFolhaPagamento.funcionarioPesquisar.nomeFantasia}" 
                                 styleClass="grid_20"/>
                    <div class="clear"/>

                    <p:outputLabel value="RG:" styleClass="grid_3" 
                                   rendered="#{managerPesquisarFolhaPagamento.pessoaFisicaPesquisar}"/> 
                    <p:inputText styleClass="grid_8" value="#{managerPesquisarFolhaPagamento.funcionarioPesquisar.rg}" 
                                 rendered="#{managerPesquisarFolhaPagamento.pessoaFisicaPesquisar}"/>
                    <div class="clear"/>

                    <br/>
                    <div class="buttonAction">
                        <p:commandButton value="Pesquisar" styleClass="ui-priority-primary"
                                         actionListener="#{managerPesquisarFolhaPagamento.pesquisar()}"
                                         update=":folhaPagamentoForm:folhasPagamentoPanel, :folhaPagamentoForm:portariasTable"
                                         id="pesquisarCommandButton" icon="ui-icon-search"/>
                    </div>
                </p:panel> 

                <p:panel id="folhasPagamentoPanel" styleClass="container_24 clearfix">
                    <p:dataTable id="portariasTable" var="item" value="#{managerPesquisarFolhaPagamento.folhasPagamentos}" 
                                 styleClass="grid_24" emptyMessage="Nenhum registro">  
                        <f:facet name="header">
                            Declarações
                        </f:facet>

                        <p:column headerText="Ação" width="50">
                            <p:button title="Visualizar"
                                      href="visualizarfolhapagamento.xhtml?vFolhaPagamento=#{item.id}"
                                      icon="ui-icon-zoomin"/>
                            <p:commandButton update="@form, :folhaPagamentoForm:folhasPagamentoPanel" title="Excluir"
                                             oncomplete="dlg.show()"
                                             icon="ui-icon-trash" >
                                <f:setPropertyActionListener target="#{managerPesquisarFolhaPagamento.folhaPagamentoDeletar}" value="#{item}" />
                            </p:commandButton>
                        </p:column>

                        <p:column headerText="Data" width="130">
                            <h:outputLabel value="#{item.dataFolhaPagamento}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputLabel>
                        </p:column>

                        <p:column headerText="Secretaria">  
                            #{item.secretaria.nome}
                        </p:column> 

                    </p:dataTable>

                    <div class="buttonAction">
                        <p:button value="Cancelar" icon="ui-icon-circle-close"
                                  href="indexfolhapagamento.xhtml" />
                    </div>

                </p:panel>

                <p:dialog id="modalDialog" header="Confirmação de remoção"
                          widgetVar="dlg" height="80" 
                          modal="true" appendToBody="true"
                          closable="false" resizable="false">

                    <h:outputText value="Tem certeza que deseja remover esta declaracao?" />
                    <div class="buttonAction">
                        <p:commandButton value="Sim"
                                         actionListener="#{managerPesquisarFolhaPagamento.deletar()}"
                                         update="@form, :folhaPagamentoForm:folhasPagamentoPanel"
                                         onsuccess="dlg.hide()"
                                         icon="ui-icon-check"/>
                        <p:commandButton value="Não" icon="ui-icon-close"
                                         oncomplete="dlg.hide()" />

                    </div>
                </p:dialog>
            </h:form>

            <h:form id="secretariaDialogForm">

                <p:dialog id="secretariaDialog" header="Secretaria" widgetVar="dlgSecretaria" modal="false"
                          width="750" resizable="false" height="350">  

                    <p:panel id="secretariaPanel" styleClass="container_24 clearfix">
                        <p:outputLabel value="Nome:" styleClass="grid_3"/>
                        <p:inputText  styleClass="grid_10" value="#{managerPesquisarFolhaPagamento.secretariaPesquisarDialog.nome}"/>

                        <p:outputLabel value="Sigla:" styleClass="grid_3"/>
                        <p:inputText  styleClass="grid_6" value="#{managerPesquisarFolhaPagamento.secretariaPesquisarDialog.sgl}"/>
                        <div class="clear" />

                        <p:outputLabel value="Secretario:" styleClass="grid_3"/>
                        <p:inputText  styleClass="grid_19" value="#{managerPesquisarFolhaPagamento.secretariaPesquisarDialog.nomeSecretario}"/>
                    </p:panel>

                    <div class="buttonAction">
                        <p:commandButton value="Pesquisar" actionListener="#{managerPesquisarFolhaPagamento.pesquisarSecretaria()}"  
                                         icon="ui-icon-search" styleClass="ui-priority-primary"
                                         process="@all" update="secretariaTable"/>

                    </div>

                    <p:panel id="dlgPanel" styleClass="container_24 clearfix">
                        <p:dataTable id="secretariaTable" var="item" value="#{managerPesquisarFolhaPagamento.secretarias}" 
                                     styleClass="grid_24" rowIndexVar="rowid" 
                                     style="white-space: pre-wrap;"
                                     rowKey="#{item.id}" rows="5" paginator="true"  
                                     paginatorPosition="bottom" emptyMessage="Nenhum registro">  
                            <f:facet name="header">
                                <p:outputLabel value="Secretaria" />
                            </f:facet>
                            <p:column headerText="Ação" width="10px;" > 
                                <p:commandButton icon="ui-icon-check"
                                                 actionListener="#{managerPesquisarFolhaPagamento.setarSecretaria(item)}"
                                                 update=":folhaPagamentoForm:secretariaInputText, @form"/>
                            </p:column>
                            <p:column headerText="Nome"> 
                                <p:outputLabel value="#{item.nome}"/>
                            </p:column>
                            <p:column headerText="Secretario">
                                <p:outputLabel value="#{item.nomeSecretario}"/>
                            </p:column>
                            <p:column headerText="Sigla">
                                <p:outputLabel value="#{item.sgl}"/>
                            </p:column>

                        </p:dataTable>
                    </p:panel>
                    <div class="buttonAction">
                        <p:commandButton value="Sair" process="@this" onclick="dlg.hide()" icon="ui-icon-close" />
                    </div>
                </p:dialog>   

            </h:form>
        </ui:define>
    </ui:composition>
</html>


